# Maintainer: omni <omni+alpine@hack.org>
pkgname=sccache
pkgver=0.8.0
pkgrel=0
pkgdesc="shared compilation cache for C/C++ and Rust"
url="https://github.com/mozilla/sccache/"
# ppc64le, riscv64 & s390x: not supported by ring crate
arch="all !ppc64le !riscv64 !s390x"
license="Apache-2.0"
makedepends="cargo openssl-dev>3 cargo-auditable"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/mozilla/sccache/archive/v$pkgver.tar.gz
	test_musl_ldd_parse.patch
	"

case "$CARCH" in
x86_64)
	# only x86_64 supports sccache-dist
	subpackages="$subpackages $pkgname-dist"
	_features="all,dist-server"
	;;
*)
	_features="all"
	;;
esac


prepare() {
	default_prepare
	cargo fetch --locked
}

build() {
	cargo auditable build --release --frozen --features $_features
}

check() {
	cargo test --frozen
}

package() {
	install -Dm0755 target/release/sccache -t "$pkgdir"/usr/bin

	case "$CARCH" in
	x86_64)
		install -Dm0755 target/release/sccache-dist \
			-t "$pkgdir"/usr/bin
		;;
	esac

	install -Dm0644 -t "$pkgdir"/usr/share/doc/"$pkgname" \
		docs/*.md
	rm "$pkgdir"/usr/share/doc/"$pkgname"/DistributedFreeBSD.md \
	   "$pkgdir"/usr/share/doc/"$pkgname"/Releasing.md
}

dist() {
	pkgdesc="$pkgdesc (dist server)"

	amove usr/bin/sccache-dist
}

sha512sums="
1b0a85ff12e9e17c39b4145adbab8706108691ad924a4dad94ee2cf6a48c4ee6a5fba47c5edd810c6767c04bea9c40e1ca0971fc8fab4af724228979446361bc  sccache-0.8.0.tar.gz
e185fc6371bcfd59b5c5243d6d4461327061b26d608680187ec49b3698a459e4dca03a0641553a690b8009bd08413d157cf03697bfad7b7d47e8a31c80f37bac  test_musl_ldd_parse.patch
"
